package com.feature.shop.user.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.feature.core.domain.PageVo;
import com.feature.core.mybatis.BaseService;
import com.feature.core.mybatis.SmartBaseMapper;
import com.feature.shop.user.api.request.ShopUserRoleListRequest;
import com.feature.shop.user.api.request.ShopUserRolePageRequest;
import com.feature.shop.user.api.vo.ShopRoleVo;
import com.feature.shop.user.api.vo.ShopUserRoleVo;
import com.feature.shop.user.mapper.ShopUserRoleMapper;
import com.feature.shop.user.converter.ShopRoleConverter;
import com.feature.shop.user.converter.ShopUserRoleConverter;
import com.feature.shop.user.model.entity.ShopRoleEntity;
import com.feature.shop.user.model.entity.ShopUserRoleEntity;

/***
 * 用户角色表Service
 */
@Service
public class ShopUserRoleService extends BaseService<ShopUserRoleEntity> {
    @Autowired
    private ShopUserRoleMapper shopUserRoleMapper;
    @Autowired
    private ShopUserRoleConverter shopUserRoleConverter;
    @Autowired
    private ShopRoleConverter shopRoleConverter;

    @Override
    public SmartBaseMapper<ShopUserRoleEntity> getSmartBaseMapper() {
        return shopUserRoleMapper;
    }

    public PageVo<ShopUserRoleVo> findPageList(ShopUserRolePageRequest req) {
        PageVo<ShopUserRoleEntity> pageData = shopUserRoleMapper.selectPageList(req.getCurPage(), req.getPageSize(), shopUserRoleConverter.pageRequestToQuery(req));
        PageVo<ShopUserRoleVo> vo = PageVo.of(pageData, shopUserRoleConverter::entityListToVO);
        return vo;

    }

    public List<ShopUserRoleVo> findList(ShopUserRoleListRequest req) {
        List<ShopUserRoleEntity> list = shopUserRoleMapper.selectList(shopUserRoleConverter.listRequestToQuery(req));
        return shopUserRoleConverter.entityListToVO(list);
    }

    @Override
    public Class<ShopUserRoleEntity> getEntityClass() {
        return ShopUserRoleEntity.class;
    }

    public List<ShopRoleVo> queryRoleByUserId(Integer userId) {
        List<ShopRoleEntity> roles = shopUserRoleMapper.queryRoleByUserId(userId);
        return shopRoleConverter.entityListToVO(roles);
    }

}
